package com.tencent.qcloud.presentation.business;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.tencent.imsdk.TIMLogLevel;
import com.tencent.imsdk.TIMManager;
import com.tencent.imsdk.TIMSdkConfig;


/**
 * 初始化
 * 包括imsdk等
 */
public class InitBusiness {

    private static final String TAG = InitBusiness.class.getSimpleName();

    private InitBusiness() {
    }

    public static void start(Context context) {
        initImsdk(context, 0);
    }

    public static void start(Context context, int logLevel) {
        initImsdk(context, logLevel);
    }


    /**
     * 初始化imsdk
     */
    private static void initImsdk(Context context, int logLevel) {
        try {
            ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            int key = appInfo.metaData.getInt("im_ui_key");
            TIMSdkConfig config = new TIMSdkConfig(key);
            config.enableLogPrint(true).setLogLevel(TIMLogLevel.values()[logLevel]);
            //初始化imsdk
            TIMManager.getInstance().init(context, config);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        //禁止服务器自动代替上报已读
        Log.d(TAG, "initIMsdk");
    }
}